﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php	

	include("../inc/joomlaInt_admin.php");
	include("../inc/inc_configuration.php");
	
	if ($jUser==0)
	{
		echo "Bitte zuerst einloggen!";
	}
	else
	{
	
		$q="SELECT gid FROM $tbl_users WHERE id=$jUser";
						$qe=mysql_query($q);
						$qeo=mysql_fetch_object($qe);
						
						$gid=$qeo->gid;
						
						if ($gid!=$admingroup)
						{
							echo "Du bist kein Admin!";
							break;
						}
		
		echo "<h1>Erfolg anlegen</h1><br>";
		
		echo '<form action="erfolg_anlegen.php" method="post">';
		
		echo "	<center><table id='tabelle' width='400'>
					<tr><th></th><th></th></tr>
					<tr>
						<td>Combination:</td>
						<td><select name='combination' Size='1'>";
		
		$lq = "SELECT c.id AS id, u.username AS username, t.name AS tname, c.active FROM $tbl_combinations c, $tbl_users u, $tbl_teams t WHERE c.userId=u.id AND c.teamId=t.id ORDER BY active";
		$lqe = mysql_query($lq);

		while($row=mysql_fetch_object($lqe))
		{
			$uid=$row->id;
			$un=$row->username;
			$tn=$row->tname;
			$active = $row->active;
			echo '<Option Value="',$uid,'">',$un,' - ',$tn,' (',$active,')</option>';
		}
			
						
		echo"				</select></td>";
		
				echo "
					<tr>
						<td>Liga:</td>
						<td><select name='liga' Size='1'>";
		
		$lq = "SELECT * FROM $tbl_leagues";
		$lqe = mysql_query($lq);

		while($row=mysql_fetch_object($lqe))
		{
			$lid=$row->id;
			$ln=$row->name;
			$sid = $row->seasonId;
			echo '<Option Value="',$lid,'">',$ln,' (',$sid,')</option>';
		}
		
		echo"				</select></td>";
		
				echo "
					<tr>
						<td>Spieler:</td>
						<td><select name='player' Size='1'>";
		
		echo '<Option Value="0">---- nur Mannschaft ----</option>';
		
		$lq = "SELECT * FROM $tbl_players ORDER BY name";
		$lqe = mysql_query($lq);

		while($row=mysql_fetch_object($lqe))
		{
			$pid=$row->id;
			$name=$row->name;
			$fn = $row->firstname;
			echo '<Option Value="',$pid,'">',$name,', ',$fn,'</option>';
		}
			
						
		echo"				</select></td>
		
		
					</tr>
					<tr>
						<td>Bezeichnung:</td>
						<td><input name='bezeichnung' type='text' size='30' maxlength='255'></td>
					</tr>
					<tr>
						<td></td>
						<td><input type='submit' value='Anlegen' class='button anlegen'></td>
					</tr>
					<tr>
						<th></th>
						<th></th>
					</tr></table></center><br><br>
					";
		
		
		echo "<h1>Erfolge</h1>";
		
		$eq="	SELECT 
				e.id,
				c.teamId,
				e.playerId,
				e.bezeichnung,
				s.number,
				t.name,
				l.name AS liga,
				u.username
	
			FROM 	$tbl_erfolge e, 
					$tbl_combinations c, 
					$tbl_season s, 
					$tbl_leagues l,
					$tbl_teams t,
					$tbl_users u
			WHERE 
				e.combinationId=c.id AND
				e.leagueId = l.id AND
				l.seasonId = s.id AND
				c.teamId = t.id AND
				c.userId = u.id
				
			ORDER BY id DESC";
			
			
		$eQe = mysql_query($eq);
		$eanz = mySQL_num_rows($eQe);
		
		$e = "";
		$erfolge="";
		
		if ($eanz>0)
		{
			while ($row = mysql_fetch_object($eQe))
			{
				$team = $row->name;
				$playerId = $row->playerId;
				$bez = $row->bezeichnung;
				$num = $row->number;
				$liga = $row->liga;
				$teamId = $row->teamId;
				$id=$row->id;
				$username=$row->username;
				
				if ($playerId==0)
				{
					$e.="	<tr>
								<td><b>$num. Saison</b></td>
								<td>$liga</td>
								<td>$username</td>
								<td>$bez</td>
								<td>mit</td>
								<td>$team</td>
								<td><img src='../img/logos/$teamId.png' width='35' height='35'></td>
								<td><a href='erfolg_entfernen.php?id=$id'>DEL</a></td>
							</tr>";
				}
				else
				{
					$pq="SELECT firstname, name FROM $tbl_players WHERE id = $playerId";
					$pqe=mysql_query($pq);
					$pqeo=mysql_fetch_object($pqe);
					$name=$pqeo->name;
					$fname=$pqeo->firstname;
					
					$player="$fname $name";
					
					$e.="	<tr>
								<td><b>$num. Saison</b></td>
								<td>$liga</td>
								<td>$username</td>
								<td>$bez</td>
								<td>mit</td>
								<td>$player</td>
								<td><img src='../img/logos/$teamId.png' width='35' height='35'></td>
								<td><a href='erfolg_entfernen.php?id=$id'>DEL</a></td>
							</tr>";
				
				}
			

			}
		
			$erfolge = "	<table id='tabelle'>
					<tr>
						<thead>
							<th colspan='8'></th>
						</thead>
					</tr>
					$e
					<tr>
						<thead>
							<th colspan='8'></th>
						</thead>
					</tr>
				</table>";

		
		
		
		}
		
		echo "<center>$erfolge</center>";
	
	}
	
?>

</body>
</html>